package com.atguigu.cmsservice.service.impl;

import com.atguigu.cmsservice.entity.CrmBanner;
import com.atguigu.cmsservice.mapper.CrmBannerMapper;
import com.atguigu.cmsservice.service.CrmBannerService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 首页banner表 服务实现类
 * </p>
 *
 * @author 老王
 * @since 2020-05-23
 */
@Service
public class CrmBannerServiceImpl extends ServiceImpl<CrmBannerMapper, CrmBanner> implements CrmBannerService {
    //分页查询首页
    @Override
    public void pageBanner(Page<CrmBanner> pageParam, QueryWrapper wrapper) {
        this.page(pageParam, wrapper);
    }

    //根据id查询
    @Override
    public CrmBanner getBannerById(String id) {
        return this.getById(id);
    }

    @Override
    public void saveBanner(CrmBanner banner) {
        this.save(banner);
    }

    //更新
    @Override
    public void updateBannerById(CrmBanner banner) {
        this.updateById(banner);
    }

    @Override
    public void removeBannerById(String id) {
        this.removeById(id);
    }

    //前台查询首页banner
    @Override
    @Cacheable(value = "banner",key = "'bannerList'")
    public List<CrmBanner> selectIndexList() {
        QueryWrapper<CrmBanner> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("id").last("limit 2");//按id降序 且只查2条
        return this.list(wrapper);
    }

}
